using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Diagnostics;

namespace WozLib.UI.Ink.Adorners
{
  public class SelectionPreviewAdorner : Adorner
  {
    private UIElement _SelectingElement;

    public UIElement SelectingElement
    {
      get { return _SelectingElement; }
      set { _SelectingElement = value; }
    }


    // Be sure to call the base class constructor.
    public SelectionPreviewAdorner(UIElement adornedElement, UIElement selectingElement)
      : base(adornedElement)
    {
      SelectingElement = selectingElement;
    }

    protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
    {
      HitTestResult hitTestResult = base.HitTestCore(hitTestParameters);

      //return new PointHitTestResult(null, hitTestParameters.HitPoint); ;

      return null;
    }

    protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
    {
      GeometryHitTestResult geometryHitTestResult = base.HitTestCore(hitTestParameters);

      return null;
    }

    // A common way to implement an adorner's rendering behavior is to override the OnRender
    // method, which is called by the layout subsystem as part of a rendering pass.
    protected override void OnRender(DrawingContext drawingContext)
    {

      try
      {

        // Get a rectangle that represents the desired size of the rendered element
        // after the rendering pass.  This will be used to draw at the corners of the 
        // adorned element.
        //Rect adornedElementRect = new Rect(
        //  new Point(
        //    (double)SelectingElement.GetValue(InkCanvas.LeftProperty),
        //    (double)SelectingElement.GetValue(InkCanvas.TopProperty)),
        //  this.SelectingElement.DesiredSize);
        Rect adornedElementRect = new Rect(this.SelectingElement.DesiredSize);
        Rect adornedElementRectInner = new Rect(5.0, 5.0, 
          this.SelectingElement.DesiredSize.Width - 10.0, this.SelectingElement.DesiredSize.Height - 10.0);

        // Some arbitrary drawing implements.
        SolidColorBrush brush = new SolidColorBrush(Colors.Black);
        brush.Opacity = 0.30;

        Pen pen = new Pen(brush, 5.0);

        SolidColorBrush brush2 = new SolidColorBrush(Colors.White);
        brush2.Opacity = 0.30;

        Pen pen2 = new Pen(brush2, 5.0);

        // Just draw a circle at each corner.
        drawingContext.DrawRectangle(Brushes.Transparent, pen, adornedElementRect);
        drawingContext.DrawRectangle(Brushes.Transparent, pen2, adornedElementRectInner);
        //drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
        //drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
        //drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
        //drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);

      }
      catch (Exception ex)
      {
        Debug.WriteLine(ex.ToString());
      }
    }
  }
}
